package com.ipfsemc.ipfsemc.controller.v1;

import com.ipfsemc.ipfsemc.model.Level;
import com.ipfsemc.ipfsemc.service.ILevelService;
import com.ipfsemc.ipfsemc.util.RespList;
import com.ipfsemc.ipfsemc.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("level")
@Api(value = "LevelController", tags = "会员等级")

public class LevelController {
    private static final Logger logger = LoggerFactory.getLogger(ApplyController.class);

    @Autowired
    private ILevelService levelService;

    @ApiOperation(value = "根据会员Id查询会员",httpMethod = "GET")

    @RequestMapping(value = "LevelById",method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name="levelId",value="会员ID",required=true,dataType="int")
    })
    public Response<Level> selectLevelByUser(Integer levelId){

        Response jsonData=new Response();
        try {
            if (null == levelId) {
                jsonData.setMessage("参数有误");
            }else{
                Level level=new Level();
                level.setLevelId(levelId);
                Level level1 = levelService.selectLeveByUser(level);

                jsonData.setCode(0);
                jsonData.setResult(level1);
            }

        } catch (Exception ex) {
            logger.error("[level][selectLevelByUser]", ex);
            jsonData.setMessage("系统错误,请稍后重试");
        }

        return jsonData;
    }



    @ApiOperation(value = "查看所有的会员",httpMethod = "GET")
    @RequestMapping(value = "listLevelAll",method = RequestMethod.GET)
    public RespList<Level> listLevelAll(){

        RespList jsonData=new RespList();
        try {


//            List<Level> list = levelService.list(null);
//
//            jsonData.setCode(0);
//            jsonData.setResult(list);

        } catch (Exception ex) {
            logger.error("[level][listLevel]", ex);
            jsonData.setMessage("系统错误,请稍后重试");
        }
        return jsonData;
    }


}
